/**
 * Copyright (C) 2013-2014 the original author or authors.
 */
package com.foreveross.bsl.mam.app.application;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import com.foreveross.bsl.mam.app.application.vo.AppVersionVo;

/**
 *
 * @author tanzhixiong
 * @2013-6-21 @上午11:26:02
 */
@Path(value = "/clients/")
public interface ClientWsApplication {

	/**
	 * 同步模块信息接口
	 *
	 * @param platform
	 * @param identifier
	 * @param version
	 * @param username
	 * @return
	 */
	@GET
	@Path("/{platform}/{identifier}/{version}")
	@Produces("application/json; charset=UTF-8")
	public Map<String, Object> getApps(@PathParam("platform") String platform,
			@PathParam("identifier") String identifier,
			@PathParam("version") String version,
			@QueryParam("username") String username);

	/**
	 * 应用验证接口
	 *
	 * @param platform
	 * @param identifier
	 * @param version
	 * @param username
	 * @return
	 */
	@POST
	@Path("/apps/{platform}/{identifier}/{version}/validate")
	@Produces("application/x-www-form-urlencoded")
	public Response validate(@PathParam("platform") String platform,
			@PathParam("identifier") String identifier,
			@PathParam("version") String version,
			@FormParam("secret") String secret,
			@FormParam("appKey") String appKey);

	/**
	 * 获取用户模块权限接口
	 *
	 * @param platform
	 * @param identifier
	 * @param version
	 * @param username
	 * @return
	 */
	@GET
	@Path("/apps/{identifier}/{username}/auth")
	@Produces("application/json; charset=UTF-8")
	public Response modulesAuth(@PathParam("identifier") String identifier,
			@PathParam("username") String version,
			@QueryParam("appKey") String appKey);

	/**
	 * 获取应用关联的所有模块接口
	 *
	 * @param platform
	 * @param identifier
	 * @param version
	 * @param username
	 * @return
	 */
	@GET
	@Path("/apps/modules/{token}")
	@Produces("application/json; charset=UTF-8")
	public Response modules(@PathParam("token") String token);

	/**
	 * 检测应用更新接口
	 *
	 * @param identifier
	 * @param platform
	 * @param appKey
	 * @return
	 */
	@GET
	@Path("/update/{platform}/{identifier}")
	@Produces("application/json; charset=UTF-8")
	public Map<String, Object> checkUpdate(
			@PathParam("identifier") String identifier,
			@PathParam("platform") String platform,
			@QueryParam("appKey") String appKey);

	/**
	 * 终端文件下载
	 *
	 * @param id
	 * @return
	 * @throws IOException
	 */
	@GET
	@Path("/files/{id}")
	@Produces(MediaType.APPLICATION_OCTET_STREAM)
	public void downFlies(@PathParam("id") String id,
			@QueryParam("appKey") String appKey) throws IOException;

	/**
	 * 模块快照接口
	 *
	 * @param identifier
	 * @param version
	 * @param appKey
	 * @return
	 */
	@GET
	@Path("/widget/{identifier}/{version}/snapshot")
	@Produces("application/json; charset=UTF-8")
	public List<Map<String, String>> widgetSnapshot(
			@PathParam("identifier") String identifier,
			@PathParam("version") String version,
			@QueryParam("appKey") String appKey);

	/**
	 * 更新应用下载次数
	 *
	 * @param version
	 * @param appKey
	 * @param platform
	 */
	@GET
	@Path("/update/appcount/{platform}/{version}")
	@Produces("application/json; charset=UTF-8")
	public Map<String, Object> updateAppDownCount(
			@PathParam("version") String version,
			@QueryParam("appKey") String appKey,
			@PathParam("platform") String platform);

	/**
	 * 获取架上应用包bundle
	 *
	 * @param appKey
	 *            应用key
	 * @param appId
	 *            应用id
	 * @param platform
	 *            应用platform
	 * @return
	 */
	@GET
	@Path("/appsDownload/{identifier}/{platform}")
	@Produces("application/json; charset=UTF-8")
	public AppVersionVo downAppPlat(@PathParam("identifier") String identifier,
			@QueryParam("appKey") String appKey,
			@PathParam("platform") String platform,
			@QueryParam("version") String version);
}
